package com.cbs.android.function.imagepick.sample;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.cbs.android.component.application.activity.CBSActivity;
import com.cbs.android.component.log.L;
import com.cbs.android.component.toast.Toast;
import com.cbs.android.function.imagecrop.ImageCropFunction;
import com.cbs.android.function.imagecrop.ImageCropHandler;
import com.cbs.android.function.imagepick.ImagePickFunction;
import com.cbs.android.function.imagepick.ImagePickHandler;

import java.util.List;

public class MainActivity extends CBSActivity {
    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toast.init(this);
    }

    public void single(View view) {
        ImagePickFunction.start(this, new ImagePickHandler() {
            @Override
            public void onPickSuccess(int requestCode, Intent intent, List<Uri> result) {
                Toast.show("success");
                ImageCropFunction.start(MainActivity.this, result.get(0), new ImageCropHandler() {
                    @Override
                    public void onCropSuccess(int i, Intent intent, Uri uri) {
                        Toast.show(uri.getPath());
                    }

                    @Override
                    public void onCancel(int i, Intent intent) {
                        Toast.show("crop cancel");
                    }
                });
            }

            @Override
            public void onCancel(int i, Intent intent) {
                Toast.show("cancel");
            }
        });
    }

    public void multi(View view) {
        ImagePickFunction.start(this, 3, new ImagePickHandler() {
            @Override
            public void onPickSuccess(int requestCode, Intent intent, List<Uri> result) {
                Toast.show("success");
                for (Uri uri : result) {
                    L.e(TAG, uri.getPath());
                }
            }

            @Override
            public void onCancel(int i, Intent intent) {
                Toast.show("cancel");
            }
        });
    }
}
